/*!
 * vinculum
 * Copyright(c) 2017 azzly
 * MIT Licensed
 */
 
'use strict';

/**
 * Module dependencies.
 * @private
 */
 
const helper = require("./helper");
const CONST = require("./CONST");
const debug = require("./debug")(__filename);

class Request{
  constructor(req){
    this.method = req.method;
    this.headers = req.headers;
    this.ip = req.headers['x-real-ip'] || req.headers['x-forwarded-for'] || req.ip;
		let o = helper.extend({},req.body);
    for(let key of Object.keys(o)){
      o[key] = helper.trim(o[key]);
    }
		this.params = helper.extend({},req.query,o);
    this.params[`__request_header__ip`] = this.ip;
    this.params[`__request_header__user_agent`] = this.headers['user-agent'];
    this.params[`__request_header__host`] = this.headers['host'];
    this.params[`__request_header__referer`] = this.headers['referer'];
  }
  
  sessionToParams(){
		this.params['__session_user__id'] = this.session.getUser().id || null;
    this.params['__session_user__roles'] = this.session.getUserRoles().join(',');
  }
}

module.exports = Request;